package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.msg.rest.service.ISysMsgTemplateService;
import com.ibeeking.found.msg.service.common.param.SysMsgTemplateParam;

import com.ibeeking.found.msg.service.common.query.SysMsgTemplateQuery;

import com.ibeeking.found.msg.service.common.vo.SysMsgTemplateParamVO;
import com.ibeeking.found.msg.service.common.vo.SysMsgTemplateVO;
import com.ibeeking.nematos.constants.enums.LogClassifyEnum;
import com.ibeeking.nematos.constants.enums.LogSourceEnum;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName SysMsgConfigController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@RestController
@RequestMapping("/msg/sysMsgTemplate/v1")
public class sysMsgTemplateController {

    @Resource
    private ISysMsgTemplateService sysMsgTemplateServiceImpl;

     /*
     *  邮件模板配置
     */
    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息模板列表查询")
    @PostMapping(value = "/listSysMsgTemplate")
    public List<SysMsgTemplateVO> listSysMsgTemplate() {
        return sysMsgTemplateServiceImpl.listAll();
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "邮件模板列表查询")
    @PostMapping(value = "/listEffectSysMsgTemplate")
    public List<SysMsgTemplateVO> listEffectSysMsgTemplate(@RequestBody SysMsgTemplateQuery query) {
        query.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return sysMsgTemplateServiceImpl.list(query);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息模板查看")
    @PostMapping(value = "/viewSysMsgTemplate/{id}")
    public SysMsgTemplateVO viewSysMsgTemplate(@PathVariable("id") Long id) {
        return sysMsgTemplateServiceImpl.view(id);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息模板查看")
    @PostMapping(value = "/listByConfigId/{configId}")
    public List<SysMsgTemplateVO> listByConfigId(@PathVariable("configId") Long configId) {
        return sysMsgTemplateServiceImpl.listByConfigId(configId);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息模板参数查看")
    @PostMapping(value = "/listSysMsgTemplateParam/{templateId}")
    public List<SysMsgTemplateParamVO> listSysMsgTemplateParam(@PathVariable("templateId") Long templateId) {
        return sysMsgTemplateServiceImpl.listSysMsgTemplateParam(templateId);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.QUERY, describe = "系统消息模板查看")
    @PostMapping(value = "/viewSysMsgTemplateByCode/{code}")
    public SysMsgTemplateVO viewSysMsgTemplateByCode(@PathVariable("code") String code) {
        return sysMsgTemplateServiceImpl.viewByCode(code);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "系统消息模板修改")
    @PostMapping(value = "/modifySysMsgTemplate")
    public Boolean modifySysMsgTemplate( @RequestBody @Validated(BaseValidationGroup.Update.class) SysMsgTemplateParam param) {
        return sysMsgTemplateServiceImpl.modify(param);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logClassify = LogClassifyEnum.OPERATION_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "邮件模板启用/禁用")
    @PostMapping(value = "/changeTemplatePublishStatus/{id}/{status}")
    public Boolean changeTemplatePublishStatus( @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return sysMsgTemplateServiceImpl.changePublishStatus(id, status);
    }

}
